package com.dongdong.controller;

import com.dongdong.em.Result;
import com.dongdong.model.TbGoods;
import com.dongdong.service.GoodsMPService;
import com.dongdong.vo.GoodsSPUVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("goodsMP")
public class GoodsMPController {

    @Autowired
    private GoodsMPService mpService;

    //查询全部
    @GetMapping("getGoodsList")
    public Result getGoodsList() {
        List<TbGoods> list = mpService.list(null);
        return Result.OK().setData(list);
    }

    //分页查询
    @GetMapping("getGoodsPage")  //RequestParam  这个注解默认是必填的  所以需要注意
    public Result getGoodsPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam Integer pageSize) {
        List<TbGoods> goodslist = mpService.getGoodsPage(pageNum, pageSize);
        return Result.OK().setData(goodslist);
    }

    //模糊查询
    @GetMapping("getGoodsDim")
    public Result getGoodsDim(@RequestBody GoodsSPUVO goodsvo){
        List<GoodsSPUVO> goods = mpService.getGoodsDim(goodsvo);
        return Result.OK().setData(goods);
    }

    //修改
    @PutMapping("UpGoods")
    public Result UpGoods(@RequestBody TbGoods goods) {
        boolean b = mpService.saveOrUpdate(goods);
        return Result.OK().setData(b);
    }

    //增加插入
    @PostMapping("InGoods")
    public Result InGoods(@RequestBody TbGoods goods) {
        boolean save = mpService.save(goods);
        return Result.OK().setData(save);
    }

    //删除
    @DeleteMapping("DeGoods")
    public Result DeGoods(@RequestParam Integer id) {
        boolean b = mpService.removeById(id);
        return Result.OK().setData(b);
    }

    //批量删除  集合
    @DeleteMapping("DeGoodsAll")
    public Result DeGoodsAll(List<Integer> ids) {
        boolean b = mpService.removeByIds(ids);
        return Result.OK().setData(b);
    }

}
